﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Sita.Entities;
using Sita.Data.Repositories;

namespace Sita.MainModule.Services
{
    public class BusinessUnitService
    {
        BusinessUnitRepository BusinessUnitRepository;

        public BusinessUnitService()
        {
            BusinessUnitRepository = new BusinessUnitRepository();
        }


        //public int AddBusinessUnit(BusinessUnit bu)
        //{
        //    BusinessUnitRepository.Add(bu);
        //    BusinessUnitRepository.StoreContext.Commit();
        //    return bu.BusinessUnitID;
        //}

        public bool ModifyBusinessUnit(BusinessUnit bu)
        {
            BusinessUnitRepository.Modify(bu);

            BusinessUnitRepository.StoreContext.Commit();

            return true;
        }

        //public IList<BusinessUnit> GetBusinessUnits()
        //{
        //    return BusinessUnitRepository.GetAll().ToList();
        //}

        //public IList<BusinessUnit> GetPaginatedBusinessUnits(int parentBUId, int pageIndex, int pageSize, string sortColumn, bool ascending, out int totalRows)
        //{
        //    DirectSpecification<BusinessUnit> Spec = new DirectSpecification<BusinessUnit>(bu => !bu.Deleted);
        //    return BusinessUnitRepository.GetAllPaginated(pageIndex, pageSize, Spec, sortColumn, ascending, out totalRows).ToList();
        //    //return BusinessUnitRepository.GetOnlyChildrenPaginated(parentBUId, pageSize, sortColumn, ascending, out totalRows);
        //}

        public BusinessUnit GetBusinessUnitByID(int buID)
        {
            return BusinessUnitRepository.GetByID(buID);
        }

        //public bool DeleteBusinessUnit(BusinessUnit bu)
        //{
        //    BusinessUnitRepository.DeleteBusinessUnit(bu);
        //    BusinessUnitRepository.StoreContext.Commit();
        //    return true;
        //}


        //public BusinessUnit GetFullBusinessUnitByID(int buID)
        //{
        //    return BusinessUnitRepository.GetFullBusinessUnitByID(buID);
        //}


        public BusinessUnit GetBusinessUnitsByUserID(int userID)
        {
            return BusinessUnitRepository.GetBusinessUnitsByUserID(userID);
        }

        public void UpdatePricesByBusinessUnitID(int businessUnitID)
        {
            BusinessUnitRepository.UpdatePricesByBusinessUnitID(businessUnitID);
        }

        //public IList<BusinessUnitResource> GetBusinessUnitResources(int businessUnitID)
        //{
        //    return BusinessUnitRepository.GetBusinessUnitResources(businessUnitID);
        //}

        //public IList<BusinessUnit> GetParentAndChildsBusinessUnitsByUserID(int userID)
        //{
        //    return BusinessUnitRepository.GetParentAndChildsBusinessUnitsByUserID(userID);
        //}

        //public IList<string> GetOldBranches(bool onlyWithGRQContracts)
        //{
        //    return BusinessUnitRepository.GetOldBranches(onlyWithGRQContracts);
        //}


        //public int RemoveChildrenResources(int buID)
        //{
        //    return BusinessUnitRepository.RemoveChildrenResources(buID);
        //}



        //public IList<Channel> GetFilteredChannelsByNameAndTechnologyAndCountryCodeAndCityObjectID(string name, string countryCode, string cityObjectID, string deviceType, string networkType, string modemPool, bool? includeShared, string Platform, int buID, Dictionary<string, string> BusinessUnitResourceTypes)
        //{
        //    IList<SIPDevice> SDData;
        //    IList<Modem> ModemData;

        //    IList<TestCaseDetailNetworkMap> MappingData;

        //    IList<Channel> ReturnData;


        //    if (Platform != null && !Platform.ToUpper().Contains("ADECEF") && !includeShared.HasValue || (includeShared.HasValue && includeShared.Value))
        //    {
        //        Platform += "-ALL";
        //    }

        //    ReturnData = new List<Channel>();

        //    if (deviceType == "SIP" || deviceType == "PSTN")
        //    {
        //        SDData = m_SIPDeviceService.GetSIPDevicesByCountryCodeByCityObjectID(countryCode, cityObjectID, buID);
        //        SDData = SDData.Where(sd => deviceType.Equals(sd.ModemType)).ToList();

        //        foreach (var CurrentSD in SDData)
        //        {
        //            if (CurrentSD.Name.ToLower().IndexOf(name.ToLower()) > -1)
        //            {
        //                ReturnData.Add(new Channel { Name = CurrentSD.Name, ObjectID = CurrentSD.ObjectID, ObjectClassID = BusinessUnitResourceTypes["ModemSIP"] });
        //            }
        //        }
        //    }
        //    else if (deviceType == "GSM" || deviceType == "CDMA" || deviceType == "ANY")
        //    {
        //        ModemData = m_ModemService.GetModemsByCountryCodeByCityObjectID(countryCode, cityObjectID, buID, Platform);

        //        MappingData = m_ModemService.GetNetworkMappingData();


        //        foreach (var Modem in ModemData)
        //        {
        //            if (Modem.Name.ToLower().IndexOf(name.ToLower()) > -1)
        //            {

        //                if ((deviceType == "ANY" && networkType == "ANY") || (MappingData.Where(md => md.ModemType == Modem.Type.ToUpper() && md.NetworkType == deviceType && md.NetworkInterface == networkType).SingleOrDefault() != null))
        //                {
        //                    ReturnData.Add(new Channel { Name = Modem.Name, ObjectID = Modem.ObjectID, ObjectClassID = BusinessUnitResourceTypes["Modem"] });
        //                }

        //            }
        //        }
        //    }

        //    return ReturnData;
        //}
    }
}
